package com.sun.example.recyclerview;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.sun.example.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

/**
 * @author tianxiaolong
 * time：2019-10-04 17:16
 * description：
 */
public class DemoActivity extends AppCompatActivity {
	public static final int MAX_CLOUNMS = 6;
	public static final int MAX_FIRST_CLOUNMS = 6;

	private static final String[] names = {
			"名字",
			"疾风剑豪",
			"卡尔玛",
			"德玛西亚之力",
			"光辉女郎",
			"德玛西亚皇子",
			"卡特",
			"阿卡里",
			"小炮",
			"宝儿姐",
			"猩红狩猎者",
			"诡术妖姬",
			"虚空行者",
			"虚空掠夺者",
			"男刀***",
			"杰",
			"汤姆",
			"杰瑞",
			"小猪佩琦",
			"艾瑞莉娅",
			"暗夜猎手",
			"时光之力",
			"自然致力",
			"黑切致力",
			"日烟套装",
			"光辉女郎1",
			"光辉女郎2",
			"光辉女郎3",
			"光辉女郎4",
			"光辉女郎5"
	};

	@Override
	protected void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_recyclerview_demo);
		RecyclerView recyclerView = findViewById(R.id.id_recyclerview);
		recyclerView.setLayoutManager(new TableLayoutManager(MAX_CLOUNMS,MAX_FIRST_CLOUNMS));
		List<List<String>> datas = new ArrayList<>();
		Random random = new Random();

		for(int i=0;i<30;i++){
			List<String> child = new ArrayList<>(6);
			child.add(names[i]);
			if(i==0){
				child.add("武力");
				child.add("智力");
				child.add("移速");
				child.add("法强");
				child.add("暴击");
				datas.add(child);
				continue;
			}
			for(int j=1;j<6;j++){
				int num = random.nextInt(100);
				child.add(String.valueOf(num));
			}
			datas.add(child);
		}
		List<String> adDtaa = new ArrayList<>();
		Observable.fromIterable(datas)
				.flatMap((Function<List<String>, ObservableSource<String>>) Observable::fromIterable).subscribe(new Observer<String>() {
			@Override
			public void onSubscribe(Disposable d) {

			}

			@Override
			public void onNext(String s) {
adDtaa.add(s);
			}

			@Override
			public void onError(Throwable e) {

			}

			@Override
			public void onComplete() {
				recyclerView.setAdapter(new DemoAdapter(adDtaa));
			}
		});

	}

	public static class Data{

	}

}
